Welcome to the Tutorials
This set of tutorials is designed to help you use an integrated coding tool, VSCode, to run experiments with the Bioenergetic Foodweb Model, built in the coding language Julia.
It will cover four core objectives
- acquire/install the
Juliaprogramming language, the Integrated Development Environment calledVSCode, and theBioenergetic Food Web Modelwritten in the Julia programming language. - Learn how to work with
Juliaprogramming, from installing packages to understanding arithmetic and plotting and data frames - Learn how to simulate a simple predator-prey (consumer-resource) model using the
DifferentialEquationspackage in Julia - Learn how to implement and use the multi-species
BioenergeticFoodWebModelin Julia
Having done these, you will then be introduced to further complexities and opportunities.
Moving from R and RStudio to Julia and VSCode
For users of R and RStudio, VSCode and Julia can be thought of as the same working team, i.e. VSCode/RStudio are the text editors that allow you to create a ‘rich text’ environment from which to run Julia/R. That being said (as to be expected) there are a few differences in the workflow that it might be worth familiarising yourself with. You can also keep Table 1 handy to help with getting over the first initial stumbling blocks.
RStudio users might be familiar with the concept of working with projects (i.e. a way of ‘containerising’ your work within a specific directory), Julia works in a similar manner. Broadly a Julia project is much more localised in that any packages that you use (install) are downloaded locally for that specific project (environment), meaning that it is possible to have multiple versions of a package installed for different projects - which is very handy from a reproducibility perspective. The details of the packages (dependencies) that you install are recorded in the Project.toml (a records of packages that have been installed and their versions - very useful when sharing code as any user can see exactly what version of a package has been used) and the Manifest.toml (all the package dependencies installed - i.e. packages that for a part of the other packages that you have installed) files, these files are machine generated and will update as you add or removed packages while you work so you don’t need to worry too much about interacting with them but its good to know what they mean/do. For an R specific analogy these files can be thought as the equivalents of the renv.lock file generated from the {renv} package.
The other thing to be aware of in Julia is multiple dispatch, more specifically that it has a very strict type system that will affect the behaviour of a function. This blog post provides a nice overview of multiple dispatch using Pokemon types but the take-home message here is that it is important that you specify the correct type of an object (something that we will cover in Tutorial 2) and that often times when you run into an error it is because of that… This may seem annoying at first but it does mean that in the long run your code is much ‘safer’ because you won’t (unknowingly) be converting and combining objects that are of different types unless you specifically specify it.
| action | R | Julia |
|---|---|---|
| checking current working directory | getwd() | pwd() |
| install a package | install.package(PACKAGE_NAME) | Pkg.add(PACKAGE_NAME)
|
| call/import a package | library(PACKAGE_NAME) | using PACKAGE_NAME |
| resolving naming conflicts (functions from different packages with the same name) | PACKAGE_NAME::function() | PACKAGE_NAME.function() |
| calling column from dataframe | df$COL_NAME | df.COL_NAME | | |
| calling the first elements of a dataframe | head() | first() |
| calling the last elements of a dataframe | tail() | last() |
How to use these tutorials
The simple idea here is to make a Julia script and add the code in these tutorials to your scripts. Make sure you annotate using the # symbol, as we do in R Scripts. We suggest that You have a script associated with each section of the table of contents on the left.